#!/bin/bash

SHELL_DIR="$(cd $(dirname $0); pwd)"
PROJECT_DIR=$1
SYSTEM_DIR=$2
system_folder_name=`ls *system* -d`
if [[ ! -d ${SYSTEM_DIR} ]]; then
	echo "无SYSTEM目录，爪巴！"
	exit 1
fi
#echo "当前项目目工作录 :$PROJECT_DIR" 
#echo "插件目录 : $SHELL_DIR"
#echo "当前项目刷机包的system目录 :$SYSTEM_DIR"
#echo -e "\e[36m      >>>>>>>>>>     .     >>>>>>>>>> \e[0m"
echo ""
echo ""

lin_dir=${PROJECT_DIR##*/}
if [ ! -d $SHELL_DIR/$lin_dir  ];then
  mkdir $SHELL_DIR/$lin_dir
fi

if [[ -f $SHELL_DIR/Insides/apktool/apktool.jar ]]; then
	ApkTool="java -jar $SHELL_DIR/Insides/apktool/apktool.jar" 
	echo "ApkTool version:" && $ApkTool -version
	
else
	echo -e "\e[36m     >>>>>>>>>   没有找到apktool   >>>>>>>> \e[0m"
	echo "   ----->请在$SHELL_DIR/Insides/apktool目录下查看是否有apktool "
	sleep 10
	exit 1
fi

if [ -d $SHELL_DIR/MIUISecurityCenter ]; then

	${su} rm -rf $SHELL_DIR/MIUISecurityCenter
fi

if [[ -f $SYSTEM_DIR/priv-app/MIUISecurityCenter/MIUISecurityCenter.apk ]]; then
	echo -e "\e[36m      >>>>>>>>>>>   开始尝试去除10S     >>>>>>>>>>> \e[0m"
	echo ""
	echo ""
	cp $SYSTEM_DIR/priv-app/MIUISecurityCenter/MIUISecurityCenter.apk $SHELL_DIR/$lin_dir/MIUISecurityCenter.apk.bak
		
	$ApkTool d -q -r -f -o $SHELL_DIR/MIUISecurityCenter $SYSTEM_DIR/priv-app/MIUISecurityCenter/MIUISecurityCenter.apk		

	if [ -d $SHELL_DIR/MIUISecurityCenter ]; then
		echo -e "\e[36m    ------------->正在去除10S    \e[0m"
		echo ""
		echo ""
		sed -i 's/const\/4 v0, 0x5/const\/4 v0, 0x0/g' $SHELL_DIR/MIUISecurityCenter/smali_classes2/com/miui/permcenter/privacymanager/g.smali
		sed -i 's/const\/16 v0, 0xa/const\/16 v0, 0x0/g' $SHELL_DIR/MIUISecurityCenter/smali_classes2/com/miui/permcenter/privacymanager/i.smali
		
		
		echo "		-------------------分隔线-------------------------"
		echo " 		                                                 "
		echo "		         尝试MIUI安全中心锁定100分                  "
		echo "		                                                  "
		echo "		-------------------分隔线-------------------------"
		n=$(grep -n "return v1" $SHELL_DIR/MIUISecurityCenter/smali_classes2/com/miui/securityscan/scanner/ScoreManager.smali | head -n 1)
		m=${n%%:*}
		sed -i "${m}iconst/16 v1, 0x64" $SHELL_DIR/MIUISecurityCenter/smali_classes2/com/miui/securityscan/scanner/ScoreManager.smali
		
		
		$ApkTool b -q -f -o $SYSTEM_DIR/priv-app/MIUISecurityCenter/MIUISecurityCenter.apk $SHELL_DIR/MIUISecurityCenter
		${su} rm -rf $SHELL_DIR/MIUISecurityCenter
		echo -e "\e[36m        去除10S成功<-----------------    \e[0m"
		echo -e "\e[32msuccess\e[0m"
		sleep 3
		exit 0
	fi
	echo -e "\e[36m        去除10S失败<-----------------    \e[0m"	
	sleep 3
	exit 1	
					
fi	

echo -e "\e[36m        ----------->找不到相关APP<--------------    \e[0m"	
echo -e "\e[36m        ----------->找不到相关APP<--------------    \e[0m"
echo -e "\e[36m        ----------->找不到相关APP<--------------    \e[0m"
sleep 3


#chmod -R 0777 $PROJECT_DIR
echo -e "\e[32mDone\e[0m"


